﻿@*@model IEnumerable<Infinity.BusinessLayer.NationalityViewModel>*@
@model IPagedList<Infinity.BusinessLayer.NationalityViewModel>
@using PagedList;
@using PagedList.Mvc;
<table>
    <tr>
        <th>
            @*@Html.DisplayNameFor(model => model.NationalityID)*@
            Nationality ID
        </th>
        <th>
            Nationality Name   @*@Html.DisplayNameFor(model => model.NationalityName)*@
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.NationalityID)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.NationalityName)
        </td>
        <td>
            @Html.ActionLink("Edit", "editeNationality", new { nID = item.NationalityID }, new { @class = "buttonstyle" })
            <button class="DeleteNationality" value="@item.NationalityID"> Delete</button>
        </td>
    </tr>
     <tr>
        <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
    </tr>
}

</table>
<table>
    <tr>
        <td>@Html.PagedListPager(Model, page => Url.Action("Index", new { page, searchBy = Request.QueryString["searchBy"], searchfor = Request.QueryString["searchfor"] }))</td>
    </tr>
</table>
<script src="~/Content/js/jquery-1.11.2.min.js"></script>
<script>

    //----- delete Nationality--------------------------------------------
    $(document).ready(function () {
        $(".DeleteNationality").click(function (a) {
            
            var caller = $(this);
            var id = $(this).val();
            var x = $(this).hasClass('fromedite');

            if (confirm("Are you sure you want to delete")) {
                $.ajax({
                    type: "POST",
                    url: "/Managerial/Nationality/DeleteNationality",
                    data: { ID: id },
                    success: function (list) {
                       
                        if (x == true) {
                            location.href = '/Managerial/Nationality/Index';
                        }
                        else {
                            $('#NationalityContainer').html(list);
                            alert("deleted Successfully");
                        }
                    },
                    error: function () {
                        //  alert("can't Delet it");
                    }
                });
            }
        })
    })

</script>

